import request from '@/utils/request'
import type { ApiResponse } from '@/types'

export interface TypeItem {
  typeId: string
  name: string
  createTimestamp: number
  updateTimestamp: number
}

export interface BackgroundItem {
  sort: number
  image: string
  link: string
  createTime: string
}

export interface UserLoginDTO {
  code: string
}

export interface UserLoginVO {
  id: number
  openid: string
  token: string
}

export const commonApi = {
  // 查询所有帖子分类 - GET /common/queryType
  getTypes: (): Promise<ApiResponse<TypeItem[]>> => {
    return request.get('/common/queryType')
  },

  // 查询轮播图 - GET /common/getBackground
  getBackground: (): Promise<ApiResponse<any>> => {
    return request.get('/common/getBackground')
  },

  // 微信登录 - POST /user/user/login
  login: (data: UserLoginDTO): Promise<ApiResponse<UserLoginVO>> => {
    return request.post('/user/user/login', data)
  },

  // 上传图片 - POST /upload
  uploadImage: (file: File): Promise<ApiResponse<any>> => {
    const formData = new FormData()
    formData.append('arg0', file)
    return request.post('/upload', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 推送微信通知 - GET /push
  push: (): Promise<ApiResponse<any>> => {
    return request.get('/push')
  }
}